<template>
  <el-tabs type="border-card"  class="tabs">
    <el-tab-pane label="登录">
      <el-form :model="form" label-width="50px">
        <el-form-item label="账号">
          <el-input v-model="form.name"/>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.pwd" show-password/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </el-tab-pane>
    <el-tab-pane label="注册">
      <el-form :model="form" label-width="50px">
        <el-form-item label="账号">
          <el-input v-model="form.name"/>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.pwd" show-password/>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="form.phone"/>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="form.email"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="register">注册</el-button>
        </el-form-item>
      </el-form>
    </el-tab-pane>
  </el-tabs>
</template>

<script>
import request from "@/axios/request";
import {ElMessage} from "element-plus";
import router from "@/router/index.js";
export default {
  name: "LoginRegister",
  data() {
    return {
      form: {
        name: null,
        pwd: null,
        phone: null,
        email: null,
      },
      rules: {}
    }
  },
  methods: {
    login() {
      request.post('/login', this.form).then((res) => {
        if (res.code === 200) {
          ElMessage({
            type: 'success',
            message: '登录成功!'
          })
          // 登陆成功后跳转到主页面
          window.location.href = '/'

        } else {
          ElMessage({
            type: 'error',
            message: res.msg
          })
        }
      })
    },
    register() {
      request.post('/register', this.form).then((res) => {
        if (res.code === 200) {
          ElMessage({
            type: 'success',
            message: '注册成功!'
          })
        } else {
          ElMessage({
            type: 'error',
            message: res.msg
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.tabs {
  border-radius: 10px;  /*圆角*/
  width: 300px;
  margin: auto;
  display: flex;
  justify-content: center;
}
:deep(.el-tabs__header) {
  border-radius: 10px;  /*圆角*/
}
:deep(.el-tabs__nav-scroll) {
  border-radius: 10px;
}
</style>